package com.carsystem.entity;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.swiftdao.entity.KeyedPersistable;
/**
 * @author JinLiang
 * @datetime 2013-1-15 下午10:53:47
 * @describe 角色实体类
 */
@SuppressWarnings("serial")
@Entity
@Table(name="CS_ROLE")
public class RoleEntity implements KeyedPersistable<Long> {
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="roleId")
	private Long id;
	@Column(nullable=false,length=20)
	private String roleName;
	@Column(length=50)
	private String roleInfo;
	@OneToMany(mappedBy="roleEntity",cascade=CascadeType.REMOVE,fetch=FetchType.LAZY)
	private Set<UserEntity> userEntities;
	@ManyToMany(fetch=FetchType.EAGER,cascade={CascadeType.REMOVE,CascadeType.PERSIST})
	@JoinTable(name="CS_ROLE_RESOURCE",
	            joinColumns={@JoinColumn(name="roleId",referencedColumnName="roleId")},
	            inverseJoinColumns={@JoinColumn(name="resourceId",referencedColumnName="resourceId")})
	private Set<ResourceEntity>resourceEntities;
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public String getRoleName() {
		return roleName;
	}
	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}
	public String getRoleInfo() {
		return roleInfo;
	}
	public void setRoleInfo(String roleInfo) {
		this.roleInfo = roleInfo;
	}
	public Set<UserEntity> getUserEntities() {
		return userEntities;
	}
	public void setUserEntities(Set<UserEntity> userEntities) {
		this.userEntities = userEntities;
	}
	public Set<ResourceEntity> getResourceEntities() {
		return resourceEntities;
	}
	public void setResourceEntities(Set<ResourceEntity> resourceEntities) {
		this.resourceEntities = resourceEntities;
	}
	public RoleEntity() {
		super();
		// TODO Auto-generated constructor stub
	}
	public RoleEntity(String roleName, String roleInfo) {
		super();
		this.roleName = roleName;
		this.roleInfo = roleInfo;
	}
}
